package com.lagou;

import org.apache.catalina.startup.Tomcat;

/**
 * Hello world!
 *
 */
public class SpringApplication
{
    private int port = 8080;
    private Tomcat tomcat;
    public  void run(Class<?> primarySource,String[] args)
    {
        //实例化一个Tomcat
        tomcat = new Tomcat();
        tomcat.setPort(port);
        try {
            //自动配置部署
            tomcat.addWebapp("/",System.getProperty("user.dir"));
            //启动tomcat
            tomcat.start();
            //阻塞tomcat，用于等待接收请求
            tomcat.getServer().await();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
